<%@ page contentType="text/html;charset=utf-8"%>
<%@ page
	import="java.io.*, java.sql.*, java.util.*, java.text.*, napal.*, util.*, napal.*,java.util.ArrayList
	"%>
<%@ page import="org.apache.ibatis.*"%>
<%@ page import="java.util.Date"%>
<%@ page import="java.util.Enumeration" %>
<%@ page import="com.oreilly.servlet.multipart.DefaultFileRenamePolicy" %>
<%@ page import="com.oreilly.servlet.MultipartRequest" %>
<%
	request.setCharacterEncoding("utf-8");
%>
<%@ include file="./Header.jsp"%>
			</td>
		</TR>
		<TR HEIGHT="100">
		<td>
		
		
<a href="giguan.jsp" class="btn btn-link btn-small">기자재관리<br></a>
> <a href="Model.jsp" class="btn btn-link btn-small"> 모델관리 </a> > 새로등록<br><br><br>
<%
	String mng = (String)session.getAttribute("managerID");
	String c = " ";
	String m = " ";
	String fullpath = "";
 	if(mng==null){ %>
	<script language=javascript>
				self.window.alert("권한이 없습니다.");
				location.href="Main.jsp?";
			</script>
<%}
 	%>
	<%	
		if(request.getParameter("cname")==""||request.getParameter("mname")==""){%>
			<script language=javascript>
		       self.window.alert("빈칸을 모두 입력하세요.");
		       location.href="ModelEnroll.jsp";
		    </script>
		<%}else{
			
			
			
			String realFolder="";
			int size = 1024*1024*5;
			String encType="utf-8";
			String savePath = application.getRealPath("upload");
			
		
		ServletContext scontext = getServletContext();
		realFolder = scontext.getRealPath("upload");
		
		
			MultipartRequest multi = new MultipartRequest(request, savePath, size, encType, new DefaultFileRenamePolicy());
			c = multi.getParameter("cname");
			m = multi.getParameter("mname");
			String fileName = multi.getFilesystemName("image");
			String originalRileName = multi.getOriginalFileName("image");
			
			Enumeration files = multi.getFileNames();
			String file1 = (String)files.nextElement();
			String name = multi.getFilesystemName(file1);
			Enumeration params = multi.getParameterNames();
			
			
			RentalHome.insertmc(c,m, name);
			fullpath = realFolder +"/" +name;
									%>
								
									<script language=javascript>
       self.window.alert("모델을 등록하였습니다.");
       location.href="Model.jsp";
    </script>
							<%	}%>
			<%= c%>
			<img src="<%=  fullpath %>"></img>				
	</TD>
</TR>

<TR HEIGHT="100">
<TD><%@ include file="./bottom.jsp"%></TD> 
</TR>
</TABLE>
</body>
</html>